#include <bits/stdc++.h>
// 2025/02/06
// tag:
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

#define int long long

struct Item {
    int w, v;
} Wave[100001];

int n, M, cnt, W, dp[100001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> M >> W;
    for (int i = 1; i <= n; i++) {
        int v, w, m;
        cin >> w >> v >> m;
        for (int j = 1; j <= m; j <<= 1) {
            cnt++;
            Wave[cnt].v = j * v;
            Wave[cnt].w = j * w;
            m -= j;
        }
        if (m) {
            cnt++;
            Wave[cnt].v = m * v;
            Wave[cnt].w = m * w;
        }
    }
    for (int i = 1; i <= cnt; i++)
        for (int j = W; j >= Wave[i].w; j--)
            dp[j] = max(dp[j], dp[j - Wave[i].w] + Wave[i].v);
    for (int i = 1; i <= M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = W; j >= 0; j--)
            for (int k = 0; k <= j; k++)
                dp[j] = max(dp[j], dp[j - k] + k * k * a + k * b + c);
    }
    cout << dp[W] << endl;
    return 0;
}